package dj.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.appsys.tools.Constants;
import dj.entity.DevUser;
import dj.service.DevUserService;



@Controller
@RequestMapping("/dev")
public class DevUserController {
	
	@Resource
	private DevUserService service;
	
	@RequestMapping("login")
	public String login(){
		return "devlogin";
	}
	
	@RequestMapping("dologin")
	public String dologin(String devCode,String devPassword,HttpSession session,HttpServletRequest request){
		DevUser devUser=service.login(devCode, devPassword);
		if(devUser!=null){
			session.setAttribute(Constants.DEV_USER_SESSION, devUser);
		return "developer/main";
		}else{
		request.setAttribute("error", "用户名或密码不正确");
		return "devlogin";
		}
	}
	
	@RequestMapping("logout")
	public String logout(HttpSession session){
		session.removeAttribute(Constants.DEV_USER_SESSION);
		return "redirect:/dev/login";
	}
	@RequestMapping("flatform/main")
	public String main(HttpSession session){
		DevUser devUser=(DevUser) session.getAttribute(Constants.DEV_USER_SESSION);
		if(devUser!=null){
		return "developer/main";
		}
		return "devlogin";
	}

}
